//
//  AESubmitOrderCommonSectionView.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/15.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AESubmitOrderCommonSectionView.h"

@interface AESubmitOrderCommonSectionView ()

@property (nonatomic, copy) NSString *title;

@property (nonatomic, copy) NSString *value;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UILabel *valueLabel;

@end

@implementation AESubmitOrderCommonSectionView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = kWhiteColor;
    self.layer.cornerRadius = 6;
    self.layer.masksToBounds = YES;
}

- (void)initWithTitleLabel {
    if (!_titleLabel) {
        CGRect frame = CGRectMake(14, (self.height - 22) * 0.5, 0, 22);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:16 weight:UIFontWeightBold] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#333333"];
        }];
    }
    float width = [objectNull(self.title) widthForFont:self.titleLabel.font] + 2 + 10;
    self.titleLabel.width = width;
    self.titleLabel.text = objectNull(self.title);
}

- (void)initWithValueLabel {
    if (!_valueLabel) {
        CGRect frame = self.titleLabel.frame;
        _valueLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#333333"];
            label.textAlignment = NSTextAlignmentRight;
        }];
    }
    float width = [objectNull(self.value) widthForFont:self.titleLabel.font] + 2;
    self.valueLabel.width = width;
    self.valueLabel.left = self.width - 14 - width;
    self.valueLabel.text = objectNull(self.value);
}


- (void)updateWithViewTitle:(NSString *)title value:(NSString *)value {
    self.title = title;
    self.value = value;
    
    [self initWithTitleLabel];
    
    [self initWithValueLabel];
}

@end
